package com.lg.erp.service.impl.zhangkai;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lg.erp.entity.JsonResult;
import com.lg.erp.entity.zhangkai.Customer;
import com.lg.erp.mapper.zhangkai.CustomerMapper;
import com.lg.erp.service.zhangkai.ICustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class CustomerServiceImpl extends ServiceImpl<CustomerMapper,Customer> implements ICustomerService {
    @Autowired
    private CustomerMapper customerMapper;
    @Override
    public List<JSONObject> findCityByProvince(String province) {
        List<String> addressByProvince = customerMapper.findAddressByProvince(province);
        ArrayList<JSONObject> jsonObjects = new ArrayList<>();
        addressByProvince.forEach(s -> {
           String s1 = "{'value':'"+s.split("-")[1]+"','label':'"+s.split("-")[1]+"'}";
            JSONObject jsonObject = JSON.parseObject(s1);
            jsonObjects.add(jsonObject);
        });
        return jsonObjects;
    }

    @Override
    public List<JSONObject> findAreaByCity(String city) {
        List<String> addressByCity = customerMapper.findAddressByCity(city);
        ArrayList<JSONObject> jsonObjects = new ArrayList<>();
        addressByCity.forEach(s -> {
           String s1 = "{'value':'"+s.split("-")[2]+"','label':'"+s.split("-")[2]+"'}";
            JSONObject jsonObject = JSON.parseObject(s1);
            jsonObjects.add(jsonObject);
        });
        return jsonObjects;
    }

    @Override
    public List<Customer> findCustomerByCondition(Customer customer) {
        return customerMapper.findCustomerByCondition(customer);
    }
}
